package com.yylending.las.common.widgets;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.airbnb.lottie.LottieAnimationView;
import com.yylending.las.R;

/**
 * Created by ying_he on 2017/7/20.<br>
 * Copyright  2017 www.yylending.com. All Rights Reserved.<br><br>
 */

public class LoadingProgressDialog extends ProgressDialog {
    private String mMsg = "";

    public LoadingProgressDialog(Context context) {
        super(context);
    }

    public LoadingProgressDialog(Context context, int theme, String msg) {
        super(context, theme);
        this.mMsg = msg;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        createDialog(getContext());
    }

    private void createDialog(final Context context){
        LayoutInflater inflater = LayoutInflater.from(context);
        //得到加载的view
        View view = inflater.inflate(R.layout.loading_progress_dialog, null);
        //加载布局
        LinearLayout layout = (LinearLayout) view.findViewById(R.id.loading_progress_dialog_ll);

        LottieAnimationView lottieAnimationView = (LottieAnimationView)view.findViewById(R.id.loading_anim_view);
        TextView msgTv = (TextView) view.findViewById(R.id.message_tv);

        if (TextUtils.isEmpty(mMsg)){
            msgTv.setVisibility(View.GONE);
        }else {
            msgTv.setVisibility(View.VISIBLE);
            msgTv.setText(mMsg);
        }

        lottieAnimationView.playAnimation();

        // 设置布局，设为全屏
        setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));

    }
}